package com.gxa.order.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gxa.common.base.RespResult;
import com.gxa.common.base.RespResultCode;
import com.gxa.order.service.ServiceOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 订单服务接口
 */
@RestController
@RequestMapping(value = "ServiceOrder")
public class ServiceOrderController {

    @Autowired
    ServiceOrderService serviceOrderService;


    /**
     * 查找所有服务订单
     * @param currentPage 当前页
     * @param pageSize 每一页条数
     */
    @GetMapping(value ="findAllServiceOrder")
    public RespResult<Page> findAllServiceOrder(Integer currentPage, Integer pageSize){
        if (currentPage != null && pageSize != null) {
            return serviceOrderService.findAllServiceOrder(currentPage,pageSize);
        }
        return RespResult.error(RespResultCode.ERR_PARAM_NOT_LEGAL.getCode(),RespResultCode.ERR_PARAM_NOT_LEGAL.getMessage());
    }

    /**
     * 通过条件获取服务订单列表
     * @param currentPage 当前页
     * @param pageSize 每一页大小
     * @param condition 条件
     */
    @GetMapping(value ="findServiceOrderByCondition")
    public RespResult<Page> findServiceOrderByCondition(Integer currentPage, Integer pageSize,String condition){
        if (currentPage != null && pageSize != null && !"".equals(condition) ) {
            return serviceOrderService.findServiceOrderByCondition(currentPage, pageSize, condition);
        }
        return RespResult.error(RespResultCode.ERR_PARAM_NOT_LEGAL.getCode(),RespResultCode.ERR_PARAM_NOT_LEGAL.getMessage());
    }

    /**
     * 更换顾问
     * @param consultant 顾问
     * @param id 服务订单id
     */
    @PostMapping("replaceConsultant")
    public RespResult replaceConsultant(String consultant,Integer id){
        if (!"".equals(consultant) && id != null) {
            return serviceOrderService.replaceConsultant(consultant,id);
        }
        return RespResult.error(RespResultCode.ERR_PARAM_NOT_LEGAL.getCode(),RespResultCode.ERR_PARAM_NOT_LEGAL.getMessage());

    }

}
